
$.extend({
    /**
     * JQuery模拟form POST提交
     * @param url
     * @param args
     */
    myPost:function (url,args) {
        var body = $(document.body),
            form = $("<form method='post'></form>"),
            input;
        form.attr({"action":url});
        $.each(args,function(key,value){
            input = $("<input type='hidden'>");
            input.attr({"name":key});
            input.val(value);
            form.append(input);
        });
        form.appendTo(document.body);
        form.submit();
        document.body.removeChild(form[0]);
    },
    myGet:function (url) {
        window.location.href=url;
    }
});

Date.prototype.format = function (fmt) {
    /** * 对Date的扩展，将 Date 转化为指定格式的String * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q)
     可以用 1-2 个占位符 * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) * eg: * (new
     Date()).pattern("yyyy-MM-dd hh:mm:ss.S")==> 2006-07-02 08:09:04.423
     * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04
     * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04
     * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04
     * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
     */
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
        "H+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S+": this.getMilliseconds() //毫秒
    };
    var week = {
        "0": "/u65e5",
        "1": "/u4e00",
        "2": "/u4e8c",
        "3": "/u4e09",
        "4": "/u56db",
        "5": "/u4e94",
        "6": "/u516d"
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};

var common = {
    date: function (dt) {
        return {
            format: function (fmt) {
                if(dt=='undefined'||dt==null){
                    return "";
                }else{
                    return new Date(dt).format(fmt);
                }
            }
        }
    },
    request: {
        getParam: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape( r[2]);
            }
            else{
                return null;
            }
        }
    },
    layer:{
        tips: function (obj, msg, operation, time, tipsMore) {

            return layer.tips(msg, obj, {
                tips: [operation, '#FF4040'],
                time: time == null ? 5000 : Number(time),
                tipsMore: true
            });
        },
        msg: function (msg, time) {

            if (time == null || isNaN(time) && Number(time) < 0) {
                time = 2000;
            } else {
                time = Number(time);
            }
            return layer.msg(msg, { time: time });
        },
        loading:function(){
            return layer.msg('加载中...', {icon: 16,shade: 0.08,time:9999999999});
        },
        confirm: function (msg, callback, cancelcallback) {
            return layer.confirm(msg,
                {
                    icon: 3,
                    shadeClose: true,
                    skin: 'layui-layer-rim',
                    shade: [0.5, '#000', true],
                    border: [6, 0.3, '#000000', true],
                    btn: ['确定','取消'],
                    scrollbar: false
                }, function (index) {
                    if (callback != null && typeof (callback) === "function") {
                        callback();
                    }
                    layer.close(index);
                }, function (index) {
                    if (cancelcallback != null && typeof (cancelcallback) === "function") {
                        cancelcallback();
                    }

                });
        },
        alert: function (msg, callback) {
            return layer.alert(msg,
                {
                    icon: 0,
                    skin: 'layui-layer-rim',
                    shade: [0.5, '#000', true],
                    border: [6, 0.3, '#000000', true],
                    scrollbar: false
                }, function (index) {
                    if (callback != null && typeof (callback) === "function") {
                        callback();
                    }
                    layer.close(index);
                });
        },
        success: function (msg, callback,btnText) {
            var btnText = btnText;
            if(btnText == "undefined" || btnText == "" || btnText == undefined){
                btnText = "确定";
            }
            return layer.alert(msg,
                {
                    icon: 1,
                    skin: 'layui-layer-rim',
                    shade: [0.5, '#000', true],
                    border: [6, 0.3, '#000000', true],
                    scrollbar: false,
                    btn: [btnText]
                }, function (index) {
                    if (callback != null && typeof (callback) === "function") {
                        callback();
                    }
                    layer.close(index);
                });
        },
        fail: function (msg, callback) {
            return layer.alert(msg,
                {
                    icon: 2,
                    skin: 'layui-layer-rim',
                    shade: [0.5, '#000', true],
                    border: [6, 0.3, '#000000', true],
                    scrollbar: false
                }, function (index) {
                    if (callback != null && typeof (callback) === "function") {
                        callback();
                    }
                    layer.close(index);
                });
        },
        open: function (url, title, width, height, cancelcallback) {
            if (width == null || width == "" || isNaN(width) || Number(width) <= 0) {
                width = 480;
            }
            if (height == null || height == "" || isNaN(height) || Number(height) <= 0) {
                height = 280;
            }
            return layer.open({
                type: 2,
                closeBtn: 1,
                title: title == null || title == "" ? false : title,
                skin: 'layui-layer-rim',
                shade: [0.01, '#000', true],
                border: [6, 0.3, '#000000', true],
                area: [width + "px", height + "px"],
                content: url,
                cancel: function (index) {
                    if (cancelcallback != null && typeof (cancelcallback) === "function") {
                        cancelcallback();
                    }
                }
            });
        },
        show: function (content, title, width, height, cancelcallback) {
            if (width == null || width == "" || isNaN(width) || Number(width) <= 0) {
                width = 480;
            }
            if (height == null || height == "" || isNaN(height) || Number(height) <= 0) {
                height = 270;
            }
            //页面层
            return layer.open({
                type: 1,
                closeBtn: 1,
                title: title == null || title == "" ? false : title,
                skin: 'layui-layer-rim', //加上边框
                area: [width, height],//宽高
                border: [6, 0.3, '#000000', true],
                //offset: (($(window).height() < height ? height + 40 : $(window).height()) - height) / 2 + 'px',
                content: content,
                cancel: function (index) {
                    if (cancelcallback != null && typeof (cancelcallback) === "function") {
                        cancelcallback();
                    }
                }
            });
        }
    }
}

